<?php

namespace App\Modules\Admin\Services\Water\Apparatus;

use App\Modules\Admin\Entities\Water\ApparatusPropertyFreeModel;

use App\Modules\Admin\Entities\Water\ApparatusPropertyFeeLogModel;
use App\Modules\Admin\Entities\Water\ApparatusElectricityLogModel;
use App\Modules\Admin\Entities\Water\ApparatusWaterRateLogModel;
use App\Modules\Admin\Services\BaseService;

class ApparatusLogService extends BaseService
{
    public function __construct(ApparatusPropertyFeeLogModel $model)
    {
        $this->model = $model;
        $this->propertyFeeLogModel = new ApparatusPropertyFeeLogModel();
        $this->electricityLogModel = new ApparatusElectricityLogModel();
        $this->waterRateLogModel = new ApparatusWaterRateLogModel();
    }
    public function getPropertyFee($params){
        $id = $params['id'];
        $list = $this->propertyFeeLogModel->where('apparatus_id',$id)->get();
        $data = [];
        foreach ($list as $item) {
            $data[] = [
                'id' => $item->id,
                'price' => $item->price/100,
                'started_at' => $item->started_at,
                'ended_at' => $item->ended_at,
            ];
        }
        return $data;
    }
    public function getElectricity($params){
        $id = $params['id'];
        $list = $this->electricityLogModel->where('apparatus_id',$id)->get();
        $data = [];
        foreach ($list as $item) {
            $data[] = [
                'id' => $item->id,
                'price' => $item->price/100,
                'started_at' => $item->started_at,
                'ended_at' => $item->ended_at,
            ];
        }
        return $data;
    }
    public function getWaterRate($params){
        $id = $params['id'];
        $list = $this->waterRateLogModel->where('apparatus_id',$id)->get();
        $data = [];
        foreach ($list as $item) {
            $data[] = [
                'id' => $item->id,
                'price' => $item->price/100,
                'started_at' => $item->started_at,
                'ended_at' => $item->ended_at,
            ];
        }
        return $data;
    }
}
